#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

#define maxn 1010
int MIN = -1000;
string name[maxn];
int score[maxn];
bool flag(pair<string, int> o1, pair<string, int> o2)
{
    return o1.second > o2.second;
}
map<string, int> m, m1; /*m记录最大值,m1进行重新统计，找到第一次达到分数的人*/
inline void solution()
{
    int n;
    string name_max; //记录结果人名
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> name[i] >> score[i];
        m[name[i]] += score[i];
    }
    vector<pair<string, int> > dic(m.begin(), m.end());
    sort(dic.begin(), dic.end(), flag);
    int temp_maxn = dic[0].second;
    for (int i = 0; i < n; i++)
    {
        m1[name[i]] += score[i]; //重新进行统计
        if (m[name[i]] == temp_maxn && m1[name[i]] >= temp_maxn)
        {
            name_max = name[i];
            break;
        }
    }
    cout << name_max;
}
int main()
{
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}